package wu_wei;

/**
 * @CLASSDESCRIPER:栈先进后出
 * @AUTHOR:伍炜
 * @PHONE:15399846320
 * @EMIAL:1973503577@qq.COM
 * @DATE:2021/1/23
 * @PARAMDESCRIPER:
 * @OUTPARAMDESCRIPER:
 */
public class WU_WEI_23_TH_Q1{
    private int maxSize  = 10;//最大长度
    private int length ;//长度
    private Object[] list;//栈数组
    private int top ;//栈顶

    private WU_WEI_23_TH_Q1(){
        //定义一个Node数组
        list = new Object[maxSize];
        //将长度初始化为0
        this.length = 0;
        //将top初始化为-1
        this.top = -1;
    }

    //获取栈元素的个数
    public int getLength(){
        return length;
    }

    //判断栈是否为空
    public boolean isEmpty(){
        return this.top == -1;
    }

    // 判断栈是否为满
    public Boolean isFull(){
        return top == maxSize - 1;
    }

    //入栈
    public void push(Object t){
        if(length <= maxSize){
            this.length++;
            list[++top] = t;
        }
    }

    //出栈
    public Object pop(){
        //判断栈是否为空，为空则无法出栈
        if (isEmpty()){
            return "栈为空";
        }
        //元素个数减1
        this.length--;
        //返回出栈的t值
        return  list[top--];
    }



    public static void main(String args[]){
        WU_WEI_23_TH_Q1 w = new WU_WEI_23_TH_Q1();
        w.push("1");//入栈
        w.push("2");//入栈
        System.out.println(w.isEmpty());//判断是否为空
        System.out.println(w.isFull());//判断是否为满
        System.out.println(w.getLength());//获取长度
        System.out.println(w.pop());//出栈
        System.out.println(w.pop());//出栈
    }

}
